package com.civ.sensor.dht.activator;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

import com.civ.sensor.dht.util.ControlGpio;
import com.civ.sensor.dht.util.DHT11;
import com.civ.sensor.dht.util.SensorThread;

public class Activator implements BundleActivator {

	private static BundleContext context;
	SensorThread st = new SensorThread();

	static BundleContext getContext() {
		return context;
	}

	public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;
		
		int GPIO_DHT11= Integer.parseInt(bundleContext.getProperty("civ.RaspiPin.GPIO_DHT11"));
		int GPIO_RELAY1= Integer.parseInt(bundleContext.getProperty("civ.RaspiPin.GPIO_RELAY1"));
		int GPIO_RELAY2= Integer.parseInt(bundleContext.getProperty("civ.RaspiPin.GPIO_RELAY2"));
		int GPIO_RELAY3= Integer.parseInt(bundleContext.getProperty("civ.RaspiPin.GPIO_RELAY3"));
		int GPIO_RELAY4= Integer.parseInt(bundleContext.getProperty("civ.RaspiPin.GPIO_RELAY4"));
		DHT11.raspiPin=GPIO_DHT11;
		ControlGpio.GPIO_RELAY1=GPIO_RELAY1;
		ControlGpio.GPIO_RELAY2=GPIO_RELAY2;
		ControlGpio.GPIO_RELAY3=GPIO_RELAY3;
		ControlGpio.GPIO_RELAY4=GPIO_RELAY4;
		
		st.start();
	}

	public void stop(BundleContext bundleContext) throws Exception {
		Activator.context = null;
		Thread.sleep(2);
		st.end();
	}

}
